//
//  ShareDetailHeadView.m
//  HappyBaby
//
//  Created by 华哥 on 15/11/30.
//  Copyright © 2015年 华哥. All rights reserved.
//

#import "ShareDetailHeadView.h"
#import "Define.h"
#import "UIImageView+WebCache.h"
#import "ShareListBottomButton.h"

@interface ShareDetailHeadView ()
@property (nonatomic, strong) UIImageView *userHeadImage;
@property (nonatomic, strong) UILabel *usernameLabel;
@property (nonatomic, strong) UILabel *shareTitle;
@property (nonatomic, strong) UILabel *shareContent;
@property (nonatomic, strong) UIImageView *shareImage;

@property (nonatomic, strong) UIView *grayLineLabel;
@property (nonatomic, strong) UILabel *tableViewTopLbale;



@end

@implementation ShareDetailHeadView

- (instancetype)initWithFrame:(CGRect)frame
{
    
    self = [super initWithFrame:frame];
    if (self)
    {
        float scaleX = kScreenWidth / 375;
        float scaleY = kScreenHeight / 667;
        
        self.userHeadImage = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 35, 35)];
        self.userHeadImage.layer.cornerRadius = 35 / 2;
        self.userHeadImage.layer.masksToBounds = YES;
        [self addSubview:_userHeadImage];
        
        self.usernameLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.userHeadImage.x + self.userHeadImage.width, self.userHeadImage.y , kScreenWidth - 75, self.userHeadImage.height)];
        self.usernameLabel.text = @"名字";
        [self addSubview:_usernameLabel];
        
        self.shareTitle = [[UILabel alloc]initWithFrame:CGRectMake(self.userHeadImage.x, self.userHeadImage.y + self.userHeadImage.height, kScreenWidth, 50)];
        self.shareTitle.text = @"分享标题";
        [self addSubview:_shareTitle];
        
        self.shareContent = [[UILabel alloc]initWithFrame:CGRectMake(self.shareTitle.x, self.shareTitle.y + self.shareTitle.height, self.shareTitle.width, 30)];
        self.shareContent.text = @"分享内容";
        self.shareContent.numberOfLines = 0;
        [self addSubview:_shareContent];
        
        self.shareImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, self.shareContent.y + self.shareContent.height, 80, 80)];
        [self addSubview:_shareImage];

        self.tableViewTopLbale = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 20)];
        self.tableViewTopLbale.text = @"评论";
        self.tableViewTopLbale.backgroundColor = [UIColor colorWithRed:234 / 255.0 green:235 / 255. blue:236 / 255.0 alpha:1];
        [self addSubview:_tableViewTopLbale];
        }
    return self;
}

- (void)setModel:(UserShareModel *)model
{
    [self.userHeadImage sd_setImageWithURL:[NSURL URLWithString:model.userInfoModel.userHeadImage] placeholderImage:[UIImage imageNamed:@"iconfont-iconfontyonghutouxiang"]];
    self.usernameLabel.text = model.userInfoModel.username;
    self.shareTitle.text = model.shareTitle;
    self.shareContent.text = model.shareContent;
    NSLog(@"%@",self.shareContent.text);
    
    CGSize shareContentSize = [self stringSizeWithFont:self.shareContent.font string:self.shareContent.text width:kScreenWidth];
  
    if (model.shareImage.length == 0)
    {
        self.shareImage.frame = CGRectMake(0, 0, 0, 0);
        self.shareContent.height = shareContentSize.height;
        self.tableViewTopLbale.y = self.shareContent.y + self.shareContent.height + 20;
    }
    
    else
    {
        self.shareContent.height = shareContentSize.height;
        self.shareImage.frame = CGRectMake(30, self.shareContent.y + self.shareContent.height, 80, 80);
        [self.shareImage sd_setImageWithURL:[NSURL URLWithString:model.shareImage] placeholderImage:nil];
        self.tableViewTopLbale.y = self.shareImage.y + self.shareImage.height + 20;
    }
    self.height = self.tableViewTopLbale.y + self.tableViewTopLbale.height + 30;
}

- (CGSize)stringSizeWithFont:(UIFont *)font string:(NSString *)string width:(CGFloat)width
{
    CGRect rect = [string boundingRectWithSize:CGSizeMake(width, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil];
    return rect.size;
}

















@end
